home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 25
/
Cream of the Crop 25.iso
/
program
/
fpk65_66.zip
/
SOURCE
/
RTL
/
DOS
/
ELLIPSE.PPI
< prev
next >
Wrap
Text File
|
1997-01-05
|
3KB
|
100 lines
{FILE: ELLIPSE.PPI }
function CalcEllipse(x,y:Integer;XRadius,YRadius:word):Integer;
var aq,bq,xq,yq,abq : Longint;
xp,yp,count : integer;
begin
XRadius:=(XRadius*10000) div XAsp;
YRadius:=(YRadius*10000) div YAsp;
aq :=XRadius * XRadius;
bq :=YRadius * YRadius;
abq:=aq * bq;
yp:=YRadius;
xp:=0;
count:=0;
{ Berechnung nach : X^2 / A^2 + Y^2 / B^2 = 1 }
{ umgestellt : X^2 * Y^2 * A^2 * B^2 = A^2*B^2 }
{ dadurch werden evtuelle Divisionen durch 0 vermieden }
{ und Integerarithmetik moeglich }
repeat
PWord(buffermem)[count ]:=x + xp;
PWord(buffermem)[count+1]:=y + yp;
PWord(buffermem)[count+2]:=x - xp;
PWord(buffermem)[count+3]:=y - yp;
xq:=xp * xp; yq:=yp * yp;
if xq * bq + yq * aq >= abq then yp:=yp-1 else xp:=xp+1;
Count:=Count+4;
until yp < 0;
CalcEllipse:=Count;
end;
Procedure _Ellipse(Count:Integer);
const aq:Integer=0;
begin
{ Das Zeichnen der Ellipse erfolgt in zwei Schleifen, um systematisch }
{ von oben nach unten zu zeichnen und somit ein staendiges Bank- }
{ umschalten zu verhindern }
while aq <> count do begin
PutPixel( PWord(buffermem)[aq] ,PWord(buffermem)[aq+3],aktcolor);
PutPixel( PWord(buffermem)[aq+2],PWord(buffermem)[aq+3],aktcolor);
aq:=aq+4;
end;
while aq <> 0 do begin
aq:=aq-4;
PutPixel( PWord(buffermem)[aq] ,PWord(buffermem)[aq+1],aktcolor);
PutPixel( PWord(buffermem)[aq+2],PWord(buffermem)[aq+1],aktcolor);
end;
end;
Procedure Fillellipse(x,y:Integer;XRadius,YRadius:word);
var Count,index:Word;
Count8:Word;
begin
_graphresult:=grOk;
if not isgraphmode then
begin
_graphresult:=grnoinitgraph;
exit;
end;
Count:=CalcEllipse(x,y,XRadius,YRadius);
if Count=0 then exit;
Count8:=Count-8;
index:=0;
while index < count do begin
while (PWord(buffermem)[index+1]=PWord(buffermem)[index+5]) and
(index < count8) do Index:=Index+4;
PatternLine(PWord(buffermem)[index],PWord(buffermem)[index+2],
PWord(buffermem)[index+3]);
Index:=Index+4;
end;
while index > 0 do begin
index:=index-4;
PatternLine(PWord(buffermem)[index],PWord(buffermem)[index+2],
PWord(buffermem)[index+1]);
while (PWord(buffermem)[index+1]=PWord(buffermem)[index-3]) and
(index > 4 ) do Index:=Index-4;
end;
if (aktColor <> aktFillSettings.Color) or (aktFillSettings.Pattern<>1)
then _Ellipse(Count);
end;
procedure Circle(x,y:integer;radius:word);
begin
_graphresult:=grOk;
if not isgraphmode then
begin
_graphresult:=grnoinitgraph;
exit;
end;
_Ellipse(CalcEllipse(x,y,radius,radius));
end;